<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['prefix'=>'coopen'],function (){
    Route::group(['prefix'=>'video'],function (){
        Route::get('list',function (){
            $model = new \App\Post();
            $post = [];
            $post['category_id'] = 18;
            $post['limit'] = isset($_GET['limit'])?$_GET['limit']:10;
            $datas =  $model->getPageListApi($post)['data'];
            foreach ($datas as $key=>$data){
                $datas[$key] = [
                    'id'    =>  $data['id'],
                    'title' =>  $data['post_title'],
                    'video' =>  $data['file']&&$data['file'][1]['savepath']?asset('storage/'.$data['file'][1]['savepath']):null,
                    'thumb' =>  asset('storage/'.$data['thumb']),
                    'sort'  =>  $data['sort'],
                    'status'    =>  $data['status']
                ];
            }
            return [
                'code'  =>1,
                'msg'   =>  'success',
                'data'  =>  $datas
            ];
        });
        Route::get('index',function (){
            //首页开屏视频
            $model = new \App\Post();
            $coopenModel = new \App\Http\Controllers\Admin\Coopen\Service\Coopen();
            $video_id = $coopenModel->get()->video_id;
            $data = $model->where('status',\App\Post::PUBLISHED)->find($video_id);
            if($data){
                $return =  [
                    'code'  =>  1,
                    'msg'   =>  'success',
                    'data'  =>  [
                        'id'    =>  $data['id'],
                        'title' =>  $data['post_title'],
                        'video' =>  $data['file']&&$data['file'][1]['savepath']?asset('storage/'.$data['file'][1]['savepath']):null,
                        'thumb' =>  asset('storage/'.$data['thumb']),
                        'status'  =>  $data['status']
                    ]
                ];
            }else{
                $return =  [
                    'code'  =>  -1,
                    'msg'   =>  'video is not found or drafted'
                ];
            }
            return $return;

        });
        Route::get('get',function (){
            $model = new \App\Post();
            if(empty($_GET['id'])){
                return [
                    'code'  =>  -1,
                    'msg'   =>  'the param is too few'
                ];
            }
            $id = $_GET['id'];
            $data = $model->where('status',\App\Post::PUBLISHED)->find($id);
            if($data){
                $return =  [
                    'code'  =>  1,
                    'msg'   =>  'success',
                    'data'  =>  [
                        'id'    =>  $data['id'],
                        'title' =>  $data['post_title'],
                        'video' =>  $data['file']&&$data['file'][1]['savepath']?asset('storage/'.$data['file'][1]['savepath']):null,
                        'thumb' =>  asset('storage/'.$data['thumb']),
                        'status'  =>  $data['status']
                    ]
                ];
            }else{
                $return =  [
                    'code'  =>  -1,
                    'msg'   =>  'video is not found or drafted'
                ];
            }
            return $return;
        });
    });
});
Route::get('wx-article-init',function (){
    if(\EasyWeChat\Payment\get_client_ip()!='::1'){
        return '';
    }
    $wechat = new \App\Service\WeChat();
    $wechat->init();
});

Route::get('wx-article-one',function (){
    if(\EasyWeChat\Payment\get_client_ip()!='::1'){
        return '';
    }
    $wechat = new \App\Service\WeChat();
    $wechat->init();
});